<template>
  <div>
    <el-card class="banner-left" shadow="hover" :body-style="{ padding: 0 }">
      <swiper
        :spaceBetween="30"
        :centeredSlides="true"
        :autoplay="{
          delay: 2500,
          disableOnInteraction: false,
        }"
        :pagination="{
          clickable: true,
        }"
        @swiper="onSwiper"
        @slideChange="onSlideChange"
        class="mySwiper"
      >
        <swiper-slide v-for="it in data" :key="it.id" @click="gotoDetail(it, router, axios)">
          <img :src="it.imgCarousel" />
          <div class="foot">
            <span>{{it.name}}</span>
            <span>{{ currIndex }}/{{ data.length }}</span>
          </div>
        </swiper-slide>
      </swiper>
    </el-card>
    <div class="img-row">
      <block v-for="(it, i) in data.slice(0, 4)" :key="it.id" @click="gotoDetail(it, router, axios)">
        <img v-if="i < 4" :src="it.imgCarousel" alt="" />
      </block>
    </div>
  </div>
</template>

<script setup>
// Import Swiper Vue.js components
import { Swiper, SwiperSlide } from "swiper/vue";
// Import Swiper styles
// Import Swiper styles
import "swiper/css";
import "swiper/css/pagination";
import "swiper/css/navigation";
// import Swiper core and required modules
import SwiperCore, { Autoplay, Pagination, Navigation } from "swiper";

import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
const router = ref(useRouter());

// install Swiper modules
SwiperCore.use([Autoplay, Pagination, Navigation]);

const props = defineProps({
  data: {
    type: Object,
    default: () => {},
  },
});

const onSwiper = (swiper) => {
  console.log(swiper);
};

const currIndex = ref(1);
const onSlideChange = (e) => {
  // console.log('slide change', e.activeIndex);
  currIndex.value = e.activeIndex + 1;
};
</script>


<style lang="less" scoped>
.swiper {
  width: 100%;
  height: 242px;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  background: #fff;

  /* Center slide text vertically */
  display: -webkit-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
}

.swiper-slide img {
  display: block;
  width: 100%;
  height: 242px;
  object-fit: cover;
}

.banner-left {
  width: 100%;
  height: 242px;
  position: relative;
  .foot {
    display: flex;
    align-items: center;
    box-sizing: border-box;
    justify-content: space-between;
    color: #fff;
    position: absolute;
    padding: 0 10px;
    font-size: 14px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    left: 0;
    bottom: 0;
    z-index: 9;
    width: 100%;
    height: 36px;
    background: linear-gradient(
      180deg,
      rgba(29, 33, 39, 0) 0%,
      rgba(29, 33, 39, 0.54) 43%,
      #1d2127 100%
    );
  }
}

.img-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 0 0 0;
  img {
    width: 64px;
    height: 64px;
    border-radius: 4px;
  }
}
</style>
